import request from '@/utils/request'

/**
 * 创建或修改副本
 * http://heartisan.online:3000/project/15/interface/api/108
 * @param {object} data
 * @param {string} data.id 副本 ID，为空为创建，否则为修改
 * @param {string} data.title 副本标题
 * @param {string} data.content 副本描述
 * @param {string} data.value 副本价值
 * @param {string} data.dueDate 到期日
 */
export const create = (data) => (request({
  url: '/instance/create',
  method: 'post',
  data
}))

/**
 * 添加任务到副本
 * http://heartisan.online:3000/project/15/interface/api/126
 * @param {object} data
 * @param {object} data.instanceId 副本 ID
 * @param {object} data.missionId 任务 ID
 */
export const addMission = (data) => (request({
  url: `/instance/addMission`,
  method: 'post',
  data
}))

/**
 * 批量添加任务副本
 * @param {object} data
 * @param {object} data.instanceId 副本 ID
 * @param {object} data.missionIds 任务 ID
 */
export const addBatchMission = (data) => (request({
  url: `/instance/addBatchMission`,
  method: 'post',
  data
}))

/**
 * 移除副本中的任务
 * http://heartisan.online:3000/project/15/interface/api/135
 * @param {object} data
 * @param {object} data.instanceId 副本 ID
 * @param {object} data.missionId 任务 ID
 */
export const removeMission = (data) => (request({
  url: `/instance/removeMission`,
  method: 'post',
  data
}))

/**
 * 删除副本
 * http://heartisan.online:3000/project/15/interface/api/144
 * @param {string} id
 */
export const del = (id) => (request({
  url: `/instance/delete/${id}`,
  method: 'post'
}))

/**
 * 我的团战列表
 * @param {object} data
 * @param {number} data.pageNumber
 * @param {number} data.pageSize
 * http://heartisan.online:3000/project/15/interface/api/153
 */
export const fetchMyInstances = ({ pageNumber, pageSize, ...data }) => (request({
  url: `/instance/fetchMyInstances/${pageNumber}/${pageSize}`,
  method: 'post',
  data
}))

/**
 * 所有团战
 * @param {object} data
 * @param {number} data.pageNumber
 * @param {number} data.pageSize
 */
export const fetchAllInstances = ({ pageNumber, pageSize, ...data }) => (request({
  url: `/instance/fetchAllInstances/${pageNumber}/${pageSize}`,
  method: 'post',
  data
}))

/**
 * 我的参加的团战
 * @param {object} data
 * @param {number} data.pageNumber
 * @param {number} data.pageSize
 */
export const fetchMyJoinInstances = ({ pageNumber, pageSize, ...data }) => (request({
  url: `/instance/fetchMyJoinInstances/${pageNumber}/${pageSize}`,
  method: 'post',
  data
}))

/**
 * 副本详情
 * http://heartisan.online:3000/project/15/interface/api/162
 * @param {string} id
 */
export const detail = (id) => (request({
  url: `/instance/${id}`,
  method: 'post'
}))

/**
 * 团战状态变更
 * @param {object} data
 * @param {string} data.id
 * @param {string} data.state
 */
export const update = (data) => (request({
  url: '/instance/updateInstanceState',
  method: 'post',
  data
}))

/**
 * 团战人员
 * instince, mission, keyResult
 */
export const instanceActor = ({ instanceId }) => (request({
  url: `/instance/instanceActor/${instanceId}`,
  method: 'post'
}))

/**
 * 流水账
 */
export const changeLog = ({ instanceId }) => request({
  url: `/changeLog/changeLog/${instanceId}`,
  method: 'post'
})
